package roy.abc.study.WebServices.JavaWSUpAndRunning.ch01.team;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class TeamUtility {
	private Map<String, Team> teamMap;

	public TeamUtility() {
		teamMap = new HashMap<String, Team>();
	}

	public Team getTeam(String name) {
		return teamMap.get(name);
	}

	public List<Team> getAllTeams() {
		List<Team> teams = new ArrayList<Team>();

		Set<String> keys = teamMap.keySet();
		for (String key : keys) {
			teams.add(teamMap.get(key));
		}

		return teams;
	}

	public void makeTestTeamMembers() {
		List<Team> teams = new ArrayList<Team>();
		
		Player chico = new Player("Leonard Marx", "Chico");
		Player groucho = new Player("Julius Marx", "Groucho");
		Player harpo = new Player("Adolph Marx", "Harpo");
		List<Player> players = new ArrayList<Player>();
		players.add(chico);
		players.add(groucho);
		players.add(harpo);
		
		Team team = new Team("Marx Brothers", players);
		
		teams.add(team);
		
		storeTeams(teams);
	}

	private void storeTeams(List<Team> teams) {
		for (Team team : teams) {
			teamMap.put(team.getName(), team);
		}
	}
}
